{include file="header.tpl"}
{* <script type="text/javascript">
$(document).ready(function() {
	$("#text1").autocomplete("getGarnuOtherList.php", 
	{
		width: 150,
		matchContains: true,
		mustMatch: true,
		minChars: 0,
		//multiple: true,
		highlight: false,
		//multipleSeparator: ",",
		selectFirst: true
	});
});
</script>
*}
<script type="text/javascript">
{literal}
$(document).ready(function()
{
  $('input:visible:enabled:first').focus();
  $('select:visible:enabled:first').focus();
  $(".delete").live('click', function(event)
  {
    $(this).parent().remove();
      change();
  });
});
function addNewRow()
{
  $('#billBook tr:last').after('<tr class="itemForRow"><td><input type="text" name="weightEntered[]" class="weightEntered" onChange="setMyRowValue(this);change(this);" \/><\/td><td><input type="text" name="touchEntered[]" class="touchEntered" onChange="setMyRowValue(this);change(this);"\/><\/td><td><input type="text" name="silverEntered[]" class="silverEntered" onChange="setMyRowValue(this);change(this);"\/><\/td><td><input type="text" name="copperEntered[]" class="copperEntered" onChange="setMyRowValue(this);change(this);" \/><\/td><td><a href="javascript:addNewRow();" class="link" >Add<\/a><\/td><td class="delete">Remove<\/td><\/tr>');
}
function addNewRowLast()
{
  $('#lastAddRow tr:last').after('<tr><td><input type="text" name="text1[]" id="text1" class="text1" \/><\/td><td><input type="text" name="text2[]" class="text2" onChange="calculateSum()" \/><\/td><td><a href="javascript:addNewRowLast();" class="link" >Add<\/a><\/td><td class="delete">Remove<\/td><\/tr>');
}

function setMyRowValue(txtObj)
{
   var row       = $(txtObj).parents('.itemForRow');
   var price     = ((parseFloat(row.find('.weightEntered').val().replace("$",""))) * (parseFloat(row.find('.touchEntered').val()))/100);
   var copp      = ((parseFloat(row.find('.weightEntered').val().replace("$",""))) - price);
   isNaN(price)   ? row.find('.silverEntered').val("") : row.find('.silverEntered').val((price).toFixed(2));
   isNaN(copp)    ? row.find('.copperEntered').val("") : row.find('.copperEntered').val((copp).toFixed(2));
   change();
}
function change()
{
  var createdSilverTot     = 0;
  var createdCopperTot     = 0;
  var createdWeightTot     = 0;
  var totalWeight          = 1;
  var totalWeightTouch     = 1;

   totalWeight      = (($("#totalWeight").val()) * ($("#totalWeightTouch").val())/100);
   totalWeightTouch = (($("#totalWeight").val()) - totalWeight);
   $("#totalSilver").val((totalWeight).toFixed(0));
   $("#totalCopper").val((totalWeightTouch).toFixed(0));


   $('.weightEntered').each(function(i)
   {
     price = $(this).val().replace("$","");
     if (!isNaN(price)) createdWeightTot += Number(price);
   });
   $('.silverEntered').each(function(i)
   {
     price = $(this).val().replace("$","");
     if (!isNaN(price)) createdSilverTot += Number(price);
   });
   $('.copperEntered').each(function(i)
   {
     price = $(this).val().replace("$","");
     if (!isNaN(price)) createdCopperTot += Number(price);
   });
   
   newTouch = createdSilverTot / createdWeightTot * 100;

   $('#createdWeightTot').val((createdWeightTot).toFixed(0));
   $('#newTouch').val((newTouch).toFixed(2));
   $('#createdSilver').val((createdSilverTot).toFixed(0));
   $('#createdCopper').val((createdCopperTot).toFixed(0));
   $('#totalCopperMain').val((createdCopperTot).toFixed(0));
   $('#pendingWeight').val((($('#totalWeight').val()) - createdWeightTot).toFixed(0));
   $('#pendingCopper').val((($('#totalCopper').val()) - ($('#totalCopperMain').val())).toFixed(0));
   $('#pendingSilver').val(($('#totalSilver').val() - $('#createdSilver').val() - ($('#pendingCopper').val()* 3/100)).toFixed(0));

}
function calculateSum()
{
	var totText2 = 0;
	$('.text2').each(function(i)
   { 
     price = $(this).val().replace("$","");
     if (!isNaN(price)) totText2 += Number(price);
   });
   
  $('#totText2').val(totText2);
}
{/literal}
</script>
<form name="form1"  method="post" autocomplete="on">
<p align="center" class="table1" colspan="8">******* Garnu ********</p>	
<div>
<table>
	  <input type="hidden" name="garnuMasterId" value="{$garnuMasterId}"/>
  <tr>&nbsp;Date &nbsp; :  
    {html_select_date prefix="curDate" start_year="-2" end_year="+1" field_order="DMY" day_value_format="%02d" time=$garnuDateMaster}
  </tr><br>
  <tr> &nbsp;Garnu : 
    <input type="text" name="garnuName" value="{$garnuNameMaster}" >
  </tr>
  <tr>
    <td> Weight : 
      <input type="text" name="totalWeight" id="totalWeight" value="{$weightMaster}" onchange="change(this);">
    </td>
    <td> Touch : 
      <input type="text" name="totalWeightTouch" id="totalWeightTouch" value="{$touchMaster}" onchange="change(this);">
    </td>
    <td> Silver : 
      <input type="text"  name="totalSilver" id="totalSilver" value="{$silverMaster}" onchange="change(this);">
    </td>  
    <td> Copper : 
      <input type="text"  name="totalCopper" id="totalCopper" value="{$copperMaster}" onchange="change(this);">
    </td>    
    <td> Return Weignt : 
      <input type="text"  name="returnWeight" value="{$retWeightMaster}">
    </td>       
  </tr>  
</table>
</div>

<center><h2>Silver & copper !</h2></center><br>
<div>
<table width="52%" cellpadding="0" cellspacing="0" border="1" align="center">
  <tr>
    <td>
      <table border="0" id="billBook" align="Left" width="30%">
        <tr class="table1">
          <th>Weight</th>
          <th>Touch</th>
          <th>Silver</th>
          <th>Copper</th>
        </tr>
      {section name="sec" loop=$garnuarray|@count}
         <tr class="itemForRow">
           <td><input type="text" name="weightEntered[]" class="weightEntered" value="{$garnuarray[sec]['weightEntered']}" onChange="setMyRowValue(this);change(this)" /></td>
           <td><input type="text" name="touchEntered[]"  class="touchEntered"  value="{$garnuarray[sec]['touchEntered']}"  onChange="setMyRowValue(this);change(this)"/></td>
           <td><input type="text" name="silverEntered[]" class="silverEntered" value="{$garnuarray[sec]['silverEntered']}" /></td>
           <td><input type="text" name="copperEntered[]" class="copperEntered" value="{$garnuarray[sec]['copperEntered']}"  /></td>
           <td><a href="javascript:addNewRow();"         class="link">Add</a></td>
           <td class="delete">Remove</td>
          </tr>
      {/section}
        <tr class="itemForRow">
          <td><input type="text" name="weightEntered[]" class="weightEntered" onChange="setMyRowValue(this);change(this)" /></td>
          <td><input type="text" name="touchEntered[]"  class="touchEntered"  onChange="setMyRowValue(this);change(this)" /></td>
          <td><input type="text" name="silverEntered[]" class="silverEntered"  /></td>
          <td><input type="text" name="copperEntered[]" class="copperEntered"  /></td>
          <td><a href="javascript:addNewRow();" class="link">Add</a></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table border="0" align="Left" width="52%">
        <tr class="itemRowForTot">
        	<td> &nbsp;</td>
        	<th align="right" width="110px;">Total</th>
          <th>
          	Weight<br />
          	 <input type="text"   name="createdWeightTot"   id="createdWeightTot"   />
          </th>
          <th>
          	New Touch
          	 <input type="text"   name="newTouch"      id="newTouch"   />
          	</th>
          <th>
            Silver<br />
            <input type="text"   name="createdSilver"   id="createdSilver"   />
            <input type="hidden" name="createdCopper"   id="createdCopper"   />
          </th>
          <th>
            Copper<br />
            <input type="text"   name="totalCopperMain[]" id="totalCopperMain" onChange="change()"/>
          </th>
        </tr>
        <tr>
        	<td> &nbsp;</td>
          <th align="right" width="110px;">Pending</th>
          <th>Weight
               <input type="text"   name="pendingWeight[]"  id="pendingWeight"   onChange="change()"/></th>
          <th>Silver
              <input type="text"   name="pendingSilver[]"   id="pendingSilver"   onChange="change()"/></th>
          <th>Copper
              <input type="text"   name="pendingCopper[]"   id="pendingCopper"   onChange="change()"/></th>
          <th align="right" width="150px;"></th>
        </tr>
        <tr><input type="submit" value="Submit" name="submitBtn" value="{if $garnuarray|@count > 0}save{else}Add{/if}"></tr>
      </table>
    </td>
  </tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" align="Left" id="lastAddRow">
  {section name="secOther" loop=$garnuOtherArray|@count}
     <tr>
       <td><input type="text" name="text1[]" id="text1" value="{$garnuOtherArray[secOther]['text1']}" /></td>
       <td><input type="text" name="text2[]" class="text2" value="{$garnuOtherArray[secOther]['text2']}" onChange="calculateSum()" /></td>
       <td><a href="javascript:addNewRowLast();" class="link">Add</a></td>
       <td class="delete">Remove</td>
      </tr>
  {/section}  
  <tr>
    <td><input type="text" name="text1[]" id="text1" class="text1" /></td>
    <td><input type="text" name="text2[]" id="text2" class="text2" onChange="calculateSum()" /></td>
    <td><a href="javascript:addNewRowLast();" class="link">Add</a></td>
  </tr>
</table>
<table width="100%">
 <tr>
  	<td>
  	 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  	 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;
  	  Total : <input type="text" name="totText2" id="totText2" value="{$garnuText2Tot}"/>
  	</td>
  </tr> 
</table>       
</div>
<div></div>
</form>
<script type="text/javascript">
{if $garnuarray|@count > 0}
  change();
  setMyRowValue();
{/if}
</script>
{include file="footer.tpl"}